package my.test;

import my.util.Log;
import my.util.handler.*;

/**
 * Created by Administrator on 2017/9/26.
 */
public class HandlerChainText {
    public static void main(String[] args) {
        Processor processor = new Processor() {
            @Override
            public Object getKey() {
                return "123";
            }

            @Override
            public Status process(HandlerContext context) {
                Object o = context.getParamString("aaa");
                Log.of(getClass()).info("process 1111111111111", o);
                return Status.CONTINUE;
            }
        };
        Object result = HandlerChain.create()
                .setName("test handler chain")
                .chain(new Processor() {
                    @Override
                    public Status process(HandlerContext context) {
                        Log.of(getClass()).info("process 000000000000");
//                        return Status.jump("123");
//                        return Status.jump(processor);
                         return Status.CONTINUE;
                    }
                })
                .chain(processor)
                .before("123", (context) -> {
                    Log.of("before").info("before processor...............");
                    return Status.CONTINUE;
                })
//                .head(new Processor() {
//                    @Override
//                    public Status process(Map<Object, Object> params, HandlerResult handlerResult) {
//                        Log.of("head").info("process head");
//                        return Status.CONTINUE;
//                    }
//                })
//                .tail((params, handlerResult) -> {
//                    Log.of("tail").info("process tail");
//                    return Status.CONTINUE;
//                })
//                .replace(0, new Processor() {
//                    @Override
//                    public Status process(Map<Object, Object> params, HandlerResult handlerResult) {
//                        Log.of(getClass()).info("process 00000000");
//                        return Status.CONTINUE;
//                    }
//                })
                .run(new HandlerContext());
    }
}
